#!/bin/bash


find_obj_impl()
{
  for i in `ls united/*.ide`
  do
    awk -F', ' '{if($2=="'$1'") {print $1} }' $i
  done
}

find_obj()
{
  find_obj_impl $* | head -n 1
}

find_model_impl()
{
  for i in `ls vc/*.ide`
  do
    awk -F', ' '{if($1=="'$1'") {print $2} }' $i
  done
}

find_model()
{
  find_model_impl $* | head -n 1
}

minmodel=0
maxmodel=5000


if [ -r table.txt ]
then
  rm table.txt
fi


while [ $minmodel -lt $maxmodel ]
do
  echo -n "$minmodel: "
  modelname=`find_model $minmodel`
  if [ "$modelname" = "" ]
  then
    echo "fail"
    let minmodel++
    continue
  fi
  modelid=`find_obj $modelname`
  if [ "$modelid" = "" ]
  then
    echo "$modelname fail"
    let minmodel++
    continue
  fi
  echo "$minmodel $modelid $modelname" >> table.txt
  echo "$modelname $modelid"

  let minmodel++
done

